<%@page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>

<%@page import="java.sql.Connection,
java.sql.PreparedStatement,
java.sql.ResultSet,
java.sql.SQLException,
java.sql.Statement,
java.util.ArrayList,
java.util.Date,
java.util.List"
%>
<%@page import= "edu.gdut.imis.goods.common.*"%>
<%@page import= "edu.gdut.imis.goods.entity.*"%>
<%@page import= "edu.gdut.imis.goods.dao.*"%>
<%@page import= "edu.gdut.imis.goods.business.*"%>
<%@page import= "edu.gdut.imis.goods.business.factory.EBOFactory"%>
<%@page import= " java.util.UUID"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
    <link rel="shortcut icon" href="favicon1.ico" />
    <link rel="stylesheet" href="css/base.css">
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/index.css">
<style>
       .item{
		   margin:60px 300px;
		   height:220px;
		   width:500px;
		   border:2px solid black;
	   }

	  
	   img{
		   height:200px;
		   width:200px;
		   
	   }
	    .left{
		 float:left;
	   }
	   .right{
		   float:right;
		   font-size:14px;
		   font-weight:2;
           margin-right:50px;
	   }
       .person-image{
           font-size:16px;
           float:left;
           margin:0px 50px;

       }
       .person{
           margin-left:250px;
       }
     
    </style>
</head>
<body>
	
    <header class="w">
        <div class="logo">
            <h1><a href="index.html">天天淘商城</a></h1>
        </div>
        <form action="/Goods/find" method="POST">
            <input type="hidden" name="submitFlag" value="find">
            <div class="search">
                <input type="text" placeholder="电视机" name="fullName" >
                
                <button type="submit">搜索</button>
                <input type="text" name="id" id="search_id" style="display:none;">
                <!-- <input type="hidden"  name="id"> -->
                
            </div>
        </form>
        <div class="hotword">                        
            <a href="#" class="style_red">优惠购首发</a>
            <a href="#">亿元优惠</a>
            <a href="#">9.9元团购</a>
            <a href="#">美满99减30</a>
            <a href="#">办公用品</a>
            <a href="#">电脑</a>
            <a href="#">通信</a>
        </div>

        <a href="showCart.jsp" target='_blank'>
            <div class="shopping-car">
                我的购物车&nbsp;&gt;
                <i class="count">8888</i>
            </div>
        </a>
       
        
    </header>

    
<%
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		//用户ID
		String id= request.getParameter("id");
		
		if(!id.equals("")&&!id.equals("null")) {
			User um = EBOFactory.getUserEBO().findByID(Integer.parseInt(id));
			
                %>
				 <ul class="person">
                    <li class="person-image">用户名:&nbsp<%=um.getName()%>
                    </li>
                    <li class="person-image">地址:&nbsp<%=um.getAddress()%>
                    </li>
                    <li class="person-image">手机:&nbsp<%=um.getMobile()%>
                    </li>
                </ul>
				<%
				String[] productItems = request.getParameterValues("productItem");
				
				Connection conn = null;
				PreparedStatement pstmt = null;
				try {
					conn = DBConnector.getConn();	
					for(int i=0;i<productItems.length;i++) {
						String[] s = null;
						s = productItems[i].split("/");
						
						GoodsModel gm = EBOFactory.getGoodsEBO().findByID(s[0]);
						int uid = Integer.parseInt(id);
						
						String oid = UUID.randomUUID().toString();
						
						String name = gm.getName();
						String Imgsrc = gm.getImg_src();
						int quantity = Integer.parseInt(s[1]);
		    			float price = gm.getPrice()*quantity;    		
		    			Date date = new Date();
		    			String time = date.toString();
		    			String description = gm.getDescription();
		    			%>
		        		<div class="item">
                            <div class="left">
		    				    <img alt="" src="upload/<%=Imgsrc%>">
		    				</div>
                            <div class="right">
		    				    <p><%=description%></p>
		    				    <span>价格:<%=price%></span>
		    				    <p>数量:<%=quantity%></p>
								<input type="text" name="description">备注
								<div>hhhhh</div>
                             </div>
		    			</div>		
		    	
		                <%
		    		
		    
						String sql = "INSERT INTO order_info VALUES(?,?,?,?,?,?,?,?)";
						pstmt = conn.prepareStatement(sql);
						pstmt.setInt(1, uid);
						pstmt.setString(2, oid);
						pstmt.setString(3, name);
						pstmt.setInt(4,quantity);
						pstmt.setFloat(5,price);
						pstmt.setString(6,time);
						pstmt.setString(7,"啊啊啊啊");
						pstmt.setString(8,"正常");
						pstmt.execute();
					} 
					
					}catch (SQLException e) {
						e.printStackTrace();
					}
					try {
						conn.close();
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				
			    	
		    		
		    	out.print("<h3><a href=\"index.html\">支付</a></h3>");
				
		    	
				session.setAttribute("uid", id);
//				resp.sendRedirect("index.html");
			}else {
		
				out.print("<h2>ID或密码错误</h2>");
				
			}
	

	
%>



	
</body>
</html>